import { writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

async function generateTest(packageName, filename) {
    const exports = await import(packageName);
    const names = Object.keys(exports)
        .filter(
            (name) =>
                name !== "default" && name !== "__esModule" && name !== "then",
        )
        .sort();

    writeFileSync(
        resolve(dirname(fileURLToPath(import.meta.url)), filename),
        `
// Generated by toolchain/side-effect-test/generate.mjs
// DO NOT MODIFY THIS FILE MANUALLY
/* eslint-disable */

import {
    ${names.join(",\n    ")}
} from "${packageName}";

export default () => {
    console.log(
        ${names.join(",\n        ")}
    )
}
`,
        "utf8",
    );
}

await Promise.all([
    generateTest("@yume-chan/scrcpy", "./src/scrcpy.js"),
    generateTest("@yume-chan/adb", "./src/adb.js"),
]);
